#include "battledialog.h"
#include "battledialogitems.h"
#include "gameanimation.h"
#include "gamedialogmanager.h"

BattleDialog::BattleDialog(GameDialogManager *m, GameDialogBg *f)
    :GameDialog(m, f)
{
    _batCard = new BattleDialogGhostCard(this);
    _batStatus = new BattleDialogGhostStatus(this);
    _batStatus->moveBy(200, -100);

    _batResult = new BattleDialogTaoResult(this);
    connect(_batResult, SIGNAL(resultUpdated()), _batCard, SLOT(OKToKill()));
    _batResult->moveBy(200, 100);

    BattleDialogButton* startButton = new BattleDialogStartButton(this);
    BattleDialogButton* cancelButton = new BattleDialogCancelButton(this);
    _buttons << startButton << cancelButton;

    BattleDialogTaoButton* red = new BattleDialogTaoRedButton(this);
    BattleDialogTaoButton* blue = new BattleDialogTaoBluButton(this);
    BattleDialogTaoButton* green = new BattleDialogTaoGreButton(this);
    BattleDialogTaoButton* yellow = new BattleDialogTaoYelButton(this);
    BattleDialogTaoButton* black = new BattleDialogTaoBlaButton(this);
    _taoButtons << red << blue << green << yellow << black;

    //rearrange normal buttons
    for(int i = 0; i<_buttons.length(); i++){
        int width = startButton->boundingRect().width();
        _buttons[i]->moveBy(-width*(_buttons.length()-1)/2+i*width, 200);
    }
    //rearrange tao buttons
    for(int i = 0; i<_taoButtons.length(); i++){
        int height = _taoButtons[i]->boundingRect().height();
        _taoButtons[i]->moveBy(-200, -height*(_taoButtons.length()-1)/2+i*height);
    }
    showAnim->addFade(this, 0, 1, 300);
    hideAnim->addFade(this, 1, 0, 300);
}


QRectF BattleDialog::boundingRect() const{
    return QRectF();
}

void BattleDialog::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){

}

int BattleDialog::execDialog(GhostSlot *s){
    _batCard->setGhostDisplay(s);
    _batStatus->setGhostData(s);
    this->startDialog();
    int num =3;
    QList<GameDialogDice*> _result = this->getDialogManager()->askDiceRoll(num);
    for(int i = 0; i< _result.length(); i++){
        switch(_result[i]->getSide()){
        case 0:
            getResultWindow()->increment(RED);
            break;
        case 1:
            getResultWindow()->increment(YELLOW);
            break;
        case 2:
            getResultWindow()->increment(BLUE);
            break;
        case 3:
            getResultWindow()->increment(GREEN);
            break;
        case 4:
            getResultWindow()->increment(BLACK);
            break;
        case 5:
            break;
        }
    }
    return 0;
}

void BattleDialog::exorGhost(){
    _batCard->exorThis();
}


